﻿using System;
using System.Collections.Generic;
using KillBill.Business.Entities;
using KillBill.Presentation.Common.WindowsForms.View;
using KillBill.Presentation.Modules.Administration.IView;
using KillBill.Presentation.Modules.Administration.Presenter;

namespace KillBill.Presentation.Modules.Administration.View
{
    public partial class EmployeeAddEditView : KillBillWinFormView, IEmployeeAddEdit
	{    
        public EmployeeAddEditPresenter Presenter { get; set; }
        public bool IsEditing { get; set; }

        public string Password
        {
            get { return txtPassword.Text; }
            set { txtPassword.Text = value; }
        }

        private Employee _employee;

		public EmployeeAddEditView()
		{
			InitializeComponent();
		    Presenter = new EmployeeAddEditPresenter(this);
            Employee = new Employee();
		    IsEditing = false;
		}

        public EmployeeAddEditView(Employee employee)
        {
            InitializeComponent();
            Presenter = new EmployeeAddEditPresenter(this);
            Employee = employee;
            IsEditing = true;
        }

        public Employee Employee
        {
            get
            {
                _employee.Person = UscPerson.Person;
                _employee.EmployeeID = UscPerson.Person.PersonID;
                _employee.EmployeeRoleID = CmbEmployeeRole.Text;
                _employee.IsActive = ChkIsActive.Checked;
                return _employee;
            }
            set
            {
                UscPerson.Person = value.Person;
                CmbEmployeeRole.SelectedText = value.EmployeeRoleID;
                ChkIsActive.Checked = value.IsActive;
                _employee = value;
            }
        }

        public List<EmployeeRole> EmployeeRoleList
        {
            set
            {
                CmbEmployeeRole.DataSource = value;
                CmbEmployeeRole.DisplayMember = "EmployeeRoleID";
            }
        }

        private void BtnSave_Click(object sender, System.EventArgs e)
        {
            if(UscPerson.IsValid) 
                Presenter.Save();
            else
                this.ShowMessage("Existen datos incorrectos");
        }

        private void EmployeeAddEditView_Load(object sender, EventArgs e)
        {
            if (CmbEmployeeRole.Items.Count >= 1) return;
            this.ShowMessage("No existen roles agregados");
            this.Close();
        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
	}
}
